#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
LL n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		string ans;
		while (n) {
			int k = n % 9;
			ans += (k < 5 ? k : k + 1) + '0';
			n /= 9;
		}
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}
	return 0;	
}
//1 2 3 4 6 7 8 9 10 11 12 13 14 16